﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Controls;
using System.Windows.Media.Media3D;
using System.Windows.Input;

namespace WPF3DTutorial.Shape {
    public abstract class Shape {
        protected Viewport3D viewport = null;

        public Shape(Viewport3D vp) {
            this.viewport = vp;
        }
        
        private void ClearViewport() {
            ModelVisual3D m;
            for (int i = viewport.Children.Count - 1; i >= 0; i--) {
                m = (ModelVisual3D)viewport.Children[i];
                if (m.Content is DirectionalLight == false)
                    this.viewport.Children.Remove(m);
            }
        }

        private void SetCamera() {
            PerspectiveCamera camera = (PerspectiveCamera)viewport.Camera;
            Point3D position = new Point3D(
                Convert.ToDouble(0),
                Convert.ToDouble(0),
                Convert.ToDouble(0)
            );
            Vector3D lookDirection = new Vector3D(
                Convert.ToDouble(0),
                Convert.ToDouble(0),
                Convert.ToDouble(0)
            );
            camera.Position = position;
            camera.LookDirection = lookDirection;
        }

        public void Show() {
            ClearViewport();
            SetCamera();

            ShowMyself();
        }

        protected abstract void ShowMyself();
    }
}
